<?php
/*
  训练 赛事 活动 发布内容.
 */

$form = $this->beginWidget('CActiveForm', array(
    "id" => "saveManageEventForm",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
$url = $control->getAjaxLinkUrl('saveManageEventContent', NULL, array(
    'eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
$updateId = $control->getAjaxContainerId();
?>
<link rel="stylesheet" type="text/css"
      href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap-datetimepicker.min.css" />
<script  type="text/javascript"
         src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-datetimepicker.min.js"/>
<script  type="text/javascript"
         src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-tooltip.js"/>
<script  type="text/javascript"
         src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-popover.js"/>

<script type="text/javascript">
    $(document).ready(function() {
        $("a[rel='tooltip']").tooltip({'placement': 'right', 'z-index': '3000'});
    });
</script>
</script>
<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function addManageEvent<?php echo $eventId; ?>() {
        var eventTheme = $('#BDynamicFormModel_media_theme_event_info').val();
        var eventCop = $('#BDynamicFormModel_media_Cop_event_info').val();
        var eventTime = $('#BDynamicFormModel_media_time_event_info').val();
        var eventAddress = $('#BDynamicFormModel_media_address_event_info').val();
        var eventInfo = $('#BDynamicFormModel_media_info_event_info').val();
        var filepath = $('#BDynamicFormModel_image_media_image_event_info').val();
        var extStart = filepath.lastIndexOf(".");
        var ext = filepath.substring(extStart, filepath.length).toUpperCase();
        if (eventTheme != "") {
            if (eventCop != "") {
                if (eventTime != "") {
                    if (eventAddress != "") {
                        if (eventInfo != "") {
                            if (filepath != "") {
                                if (ext == ".BMP" || ext == ".PNG" || ext == ".GIF" || ext == ".JPG" || ext == ".JPEG") {
                                    var formData = new FormData($("#saveManageEventForm")[0]);
                                    $.ajax({
                                        url: '<?php echo $url; ?>',
                                        type: 'POST',
                                        data: formData,
                                        //datatype: 'json',
                                        // async: false,
                                        beforeSend: function() {
                                            $("#ajax-loaderdiv").show();
                                        },
                                        success: function(html) {
                                            // on success do some validation or refresh the content div to display the uploaded images 
                                            jQuery("#<?php echo $updateId; ?>").html(html);
                                        },
                                        complete: function() {
                                            $("#ajax-loaderdiv").hide();
                                        },
                                        error: function(data) {
                                            alert("There may a error on uploading. Try again later");
                                        },
                                        cache: false,
                                        contentType: false,
                                        processData: false
                                    });
                                } else
                                    alert("图片限于bmp,png,gif,jpeg,jpg格式");
                            } else
                                alert("请上传图片")
                        } else
                            alert("请输入详情");
                    } else
                        alert("请输入地址");
                } else
                    alert("请选择时间");
            } else
                alert("请输入参加条件");
        } else
            alert("请输入主题");

        return false;
    }
</script>
<script type="text/javascript">
    $(function() {
        $('#activeTime-timepicker1').datetimepicker({
            language: 'pt-BR'
        });
        $('#expireTime-timepicker1').datetimepicker({
            language: 'pt-BR'
        });
        $('#offsetOfBookingStartTime-timepicker1').datetimepicker({
            language: 'pt-BR'
        });
        $('#offsetOfBookingEndTime-timepicker1').datetimepicker({
            language: 'pt-BR'
        });
        $('#timeSlotStartTime-timepicker1').datetimepicker({
            language: 'pt-BR'
        });
//        $('#datetimepicker1').datetimepicker({
//          language: 'pt-BR'                   //该样式可以显示为：2014-07-16 22:45:03，需要修改时间样式：data-format="yyyy-MM-dd hh:mm:ss"
//        });
    });


// this script for collecting the form data and pass to the controller action and doing the on success validations
    function saveBookableTimeSlot() {

        var formData = new FormData($("#message-form")[0]);
        //var formElement = document.getElementById("message-form");
        //var formData = new FormData(formElement);

        $.ajax({
            url: '<?php echo $url; ?>',
            type: 'POST',
            data: formData,
            datatype: 'json',
            // async: false,
            beforeSend: function() {
                $("#ajax-loaderdiv").show();
            },
            success: function(data) {
                // on success do some validation or refresh the content div to display the uploaded images 
                jQuery("#<?php echo $updateId; ?>").html(data);
                //alert(data);
            },
            complete: function() {
                $("#ajax-loaderdiv").hide();
                $("#myModal").modal("hide");
            },
            error: function() {
                alert("There may a error on uploading. Try again later");
            },
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    }

</script>
<legend>
    <h4>
        <?php echo $control->getAjaxLink(array('name' => '活动列表', 'id' => 'showManage')); ?>\
        <?php echo $control->getAjaxLink(array('name' => '管理活动', 'id' => 'manageEvent'), array('eventId' => $eventId, 'manageView' => $manageView)); ?>\
        <?php echo '管理活动内容'; ?>
    </h4>
</legend>

<?php
if (!isset($model))
    $model = new BDynamicFormModel ();

//$eventNameField = 'media_name_event_info';
//$eventDescriptionField = 'media_description_event_info';
$eventImageField = 'image_media_image_event_info';

//$eventTypeField = 'media_eventTypeId_event_info';
$eventThemeField = 'media_theme_event_info';
$eventCopField = 'media_Cop_event_info';
$eventTimeField = 'media_time_event_info';
$eventAddressField = 'media_address_event_info';
$eventInfoField = 'media_info_event_info';
$model->addField($eventThemeField);
$model->addField($eventAddressField);
$model->addField($eventTimeField);
$model->addField($eventInfoField);
$model->addField($eventCopField);
$model->addField($eventImageField);
$eventTable = new BAEventSheet();
$event = $eventTable->getListById($eventId);


if ($contentId > 0) {
    $manageEventContentTable = new BAEventSheet();
    $eventContent = $manageEventContentTable->getListById($contentId);
    $eventContentView = $manageEventContentTable->getView();
    $themeItem = $eventContent->getItem('theme');
    $imageItem = $eventContent->getItem('image');
    $addressItem = $eventContent->getItem('address');
    $timeItem = $eventContent->getItem('time');
    $infoItem = $eventContent->getItem('info');
    $copItem = $eventContent->getItem('Cop');
    if ($themeItem instanceof BTreeItem) {
        $theme = $themeItem->getValue();
        $model->$eventThemeField = $theme;
    }

    if ($imageItem instanceof BTreeItem) {
        $image = $imageItem->getValue();
        $model->$eventCopField = $image;
    }
    if ($addressItem instanceof BTreeItem) {
        $address = $addressItem->getValue();
        $model->$eventAddressField = $address;
    }
    if ($timeItem instanceof BTreeItem) {
        $time = $timeItem->getValue();
        $model->$eventTimeField = $time;
    }
    if ($infoItem instanceof BTreeItem) {
        $info = $infoItem->getValue();
        $model->$eventInfoField = $info;
    }
    if ($copItem instanceof BTreeItem) {
        $cop = $copItem->getValue();
        $model->$eventCopField = $cop;
    }
}
$eventName = $event->getItem('name')->getValue();
?>
<?php
$app = Blyn::app()->getActiveApp();
?>

<table class="table table-hover">
    <colgroup>
        <col class="span2">
        <col class="span4">
        <col class="span4">
    </colgroup>
    <thead>
        <tr>
            <th><?php echo $eventName ?></th>
            <th></th>
            <th><?php echo '说明'; ?></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <?php echo '主题'; ?>
            </td>
            <td>
                <?php
                echo CHtml::activeTextField($model, $eventThemeField, array('placeholder' => 'theme', 'required' => true));
                ?>
                <!--                    &nbsp;&nbsp;&nbsp;&nbsp;<a id="CreateNewType_clink" role="button" data-toggle="modal" class="btn disabled" style="font-size: 12px;margin-top: -12px;">创建新类型</a>-->
            </td>
            <td></td>
        </tr>


        <tr>
            <td> <?php echo '地点'; ?> </td>
            <td>
                <?php
                echo CHtml::activeTextField($model, $eventAddressField, array('placeholder' => 'address' . '...', 'required' => true));
                ?>
            </td>
            <td></td>

        </tr> 



        <tr><td> <?php echo '参加条件'; ?> </td>
            <td>
                <?php
                echo CHtml::activeTextField($model, $eventCopField, array('placeholder' => 'condition of participation' . '...', 'required' => true));
                ?>
            </td>
            <td></td>   


        </tr> 



        <tr><td> <?php echo '时间'; ?> </td>
            <td>
                <div id="timeSlotStartTime-timepicker1" class="input-append">
                    <?php
                    echo CHtml::activeTextField($model, $eventTimeField, array('data-format' => "yyyy-MM-dd hh:mm:ss", 'type' => "text", 'placeholder' => '09:00:00', 'required' => true));
                    ?>
                    <span class="add-on">
                        <i data-time-icon="icon-time" data-date-icon="icon-calendar">
                        </i>
                    </span>
                </div>
                <?php
//echo CHtml::activeTimeField($model, $eventFoundTimeField, array('placeholder' => 'foundtime' . '...', 'required' => true));
                ?>
            </td>
            <td></td>
        </tr> 

        <tr><td> <?php echo '详情'; ?> </td>
            <td>
                <?php
                echo CHtml::activeTextArea($model, $eventInfoField, array('placeholder' => 'info' . '...', 'required' => true));
                ?>
            </td>
            <td></td>
        </tr>
        </tr>  
        <tr><td> <?php echo '相关图片' ?> </td>
            <td>
                <?php
                echo CHtml::activeFileField($model, $eventImageField, array('placeholder' => 'image' . '...', 'required' => true));
                if ($model->$eventImageField != NULL) {
                    $imageUrl = Yii::app()->request->baseUrl . $model->$eventImageField;
                    echo "<img src=" . $imageUrl . " width=50 height=50 />";
                }
                ?>
            </td>
            <td></td>
        </tr>   

    </tbody>
</table>
<?php
$this->endWidget();
//echo CHtml::endForm();
?>
<button class="btn" onclick="javascript:addManageEvent<?php echo $eventId; ?>()"><?php echo '保存' ?></button>

